package util

import (
	"github.com/xuri/excelize/v2"
	"strconv"
	"tuowei.com/app/admin/models"
)

// 到B++了，够了，不够再加
func getCell(cell int32) string {
	if cell >= 65 && cell <= 90 {
		return string(cell)
	}
	if cell > 90 && cell <= 116 {
		return "A" + string(cell-91+'A')
	}
	if cell > 116 && cell <= 142 {
		return "B" + string(cell-117+'A')
	}

	return string(cell)
}
func MakeExcel(header []string, students []models.SysStudent) *excelize.File {
	f := excelize.NewFile()
	sheet := "Sheet1"

	var cell = 'A'
	// 添加第一行的头信息
	for _, v := range header {
		f.SetCellValue(sheet, getCell(cell)+"1", v)
		cell++
	}
	// 添加数据
	cell = 'A'
	for k, stu := range students {
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.Name)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.Phone)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.Id)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.IdCard)
		cell++
		if stu.IdCard != "" && len(stu.IdCard) >= 18 {
			f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.IdCard[6:10]+"/"+stu.IdCard[10:12]+"/"+stu.IdCard[12:14])
		} else {
			f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		}
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.College.CollegesName)
		cell++
		if stu.TeachRecommender > 0 {
			f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), "教师推荐")
		} else if stu.Recommender > 0 {
			f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), "学生推荐")
		} else if stu.SerialNum == "00002" || stu.SerialNum == "00003" {
			f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), "原始数据导入")
		} else {
			f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), "系统录入")
		}
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.QQ)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.KeBie)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++

		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.Faculty)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.Major)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.CollegeClass)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.TrainingDays)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), stu.Explain)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		cell++
		f.SetCellValue(sheet, getCell(cell)+strconv.Itoa(k+2), nil)
		//cell++
		//f.SetCellValue(sheet, string(cell)+strconv.Itoa(k+2), stu.AreaPoint.Name)
		//cell++
		//f.SetCellValue(sheet, string(cell)+strconv.Itoa(k+2), stu.College.CollegesName)
		//cell++
		//f.SetCellValue(sheet, string(cell)+strconv.Itoa(k+2), stu.ShenBenYear)
		//cell++
		//f.SetCellValue(sheet, string(cell)+strconv.Itoa(k+2), stu.KeBie)
		//cell++
		//// 免受课程
		//courseNameArr := make([]string, 0)
		//offlineOrders := stu.OfflineOrders
		//for _, v := range offlineOrders {
		//	if v.Course != nil {
		//		for _, vv := range v.Course {
		//			courseNameArr = append(courseNameArr, vv.Name)
		//		}
		//	}
		//}
		//var courseName string
		//if len(courseNameArr) > 0 {
		//	courseName = strings.Join(courseNameArr, "|")
		//}
		//f.SetCellValue(sheet, string(cell)+strconv.Itoa(k+2), courseName)
		//cell++
		//f.SetCellValue(sheet, string(cell)+strconv.Itoa(k+2), stu.UserType)
		cell = 'A'

	}
	return f

}
